<template>
  <div>
    <el-row class="allAttention">
      <div>全部关注</div>
    </el-row>
    <div v-if="attention_user.length">
      <div class="attention" v-for="item in attention_user" :key="item.user_id">
        <el-row align="middle" type="flex">
          <el-col :span="3">
            <div>
              <el-avatar
                :src="item.header_pic"
                shape="square"
                :size="60"
              ></el-avatar>
            </div>
          </el-col>
          <el-col :span="17">
            <p class="user_name">{{ item.username }}</p>
            <p class="user_sign">
              {{
                item.self_sign ? item.self_sign : '这个人很懒，什么也没留下...'
              }}
            </p>
          </el-col>
          <el-col :span="4">
            <el-button
              type="danger"
              size="mini"
              @click="deleteAttention(item.user_id)"
              >取消关注</el-button
            >
          </el-col>
        </el-row>
      </div>
    </div>
    <el-row v-else>
      <div style="text-align: center">暂无关注的用户信息...</div>
    </el-row>
  </div>
</template>

<script>
export default {
  data () {
    return {
      user_id: JSON.parse(sessionStorage.getItem('user')).user_id,
      attention_user: []
    }
  },
  created () {
    this.getUserAttention()
  },
  methods: {
    async getUserAttention () {
      const { data: res } = await this.$http.post('/user_attention', { userId: this.user_id })
      this.attention_user = res
    },
    async deleteAttention (id) {
      const { data: res } = await this.$http.post('/delete_attention', { user_id: this.user_id, attention_user_id: id })
      if (res.status !== 201) return this.$message.info('取消关注失败！')
      this.$message.success('取消关注成功！')
      this.getUserAttention()
    }
  }
}
</script>

<style lang="less" scoped>
.allAttention {
  padding-bottom: 15px;
  margin-bottom: 15px;
  border-bottom: 1px solid #ebeef5;
  font-size: 18px;
}

.attention {
  padding-bottom: 15px;
  margin-bottom: 15px;
  border-bottom: 1px solid #ebeef5;
}

.el-avatar {
  border-radius: 50%;
}

.user_name {
  font-size: 16px;
  margin-bottom: 5px;
  margin-top: 12px;
}

.user_sign {
  font-size: 12px;
}
</style>
